package touhou.base;

import java.awt.Canvas;
import java.awt.Point;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

import touhou.entity.Bullet;
import touhou.utils.BulletFactory;
import touhou.game.Projectile;
import touhou.rule.BulletMovableDriver;

/**
 * Implementation de ShootStrategy qui permet de tirer des projectiles avec le clavier (dans le jeu).
 */
public class ShootStrategyKeyboard extends KeyAdapter implements ShootStrategy {
	
	private static BulletFactory facto;
	private boolean shooting;
	
	private final int SPEED = 25;
	
	public ShootStrategyKeyboard(Canvas canvas) {
		shooting = false;
		facto = BulletFactory.getInstance(canvas);
	}

	@Override
	public void keyPressed(KeyEvent event) {
		int keycode = event.getKeyCode();
		if (keycode == KeyEvent.VK_SPACE) {
			shooting = true;
		}
	}
	
	@Override
	public void keyReleased(KeyEvent event) {
		int keycode = event.getKeyCode();
		if (keycode == KeyEvent.VK_SPACE) {
			shooting = false;
		}
	}
	
	@Override
	public ArrayList<Projectile> getProjectiles() {
		ArrayList<Projectile> proj = new ArrayList<Projectile>();
		if (shooting) {
			Bullet myBullet = facto.createBullet();
			BulletMovableDriver bulletDriver = new BulletMovableDriver();
			MoveStrategyTarget tarStr = new MoveStrategyTarget(new Point(0,100),new Point(0,0), SPEED);
			bulletDriver.setStrategy(tarStr);
			myBullet.setDriver(bulletDriver);
			proj.add(myBullet);
			return proj;
		}
		return proj;
	}

}
